<?php

namespace app\yue\home;

use think\worker\Server;

class Worker extends Server
{
    protected $socket = 'websocket://wx.hnw.net:2346';
    protected $context = array(
    'ssl' => array(
        // 使用绝对路径
            'local_cert'  => '/www/wdlinux/nginx-1.8.1/sslkey/213986206790352.pem', // 也可以是crt文件
            'local_pk'    => '/www/wdlinux/nginx-1.8.1/sslkey/213986206790352.key',
            'verify_peer' => false,
        )
    );
    protected $transport = 'ssl';
    /**
     * 收到信息
     * @param $connection
     * @param $data
     */
    public function onMessage($connection, $data)
    {
        $connection->send(json_encode($_SERVER));
    }

    /**
     * 当连接建立时触发的回调函数
     * @param $connection
     */
    public function onConnect($connection)
    {
        var_dump($_SERVER);
    }

    /**
     * 当连接断开时触发的回调函数
     * @param $connection
     */
    public function onClose($connection)
    {
        
    }

    /**
     * 当客户端的连接上发生错误时触发
     * @param $connection
     * @param $code
     * @param $msg
     */
    public function onError($connection, $code, $msg)
    {
        echo "error $code $msg\n";
    }

    /**
     * 每个进程启动
     * @param $worker
     */
    public function onWorkerStart($worker)
    {

    }
}